<?php require_once("../../includes_view/header.php"); ?>
<?php
$acao = "HISTORICO-OFICINA";
require_once("regras/controlador/relatorioController.php");
?>
<script type="text/javascript">
	$(document).ready(function(){		
		$('#txtplaca').mask('aaa-9999');
	});
</script>
<div id="sistema">
    <div id="migalhas">
        <a class="mig1">Relatório</a>
        <a class="mig2">Histórico Oficina</a>
    </div>
    <div id="pesquisa">
        <fieldset><legend>&nbsp; Pesquisar &nbsp;</legend>
            <form name="frmPesquisarRelatorio" id="frmPesquisarRelatorio" method="POST" action="">
                <div>
                    <label>Placa:</label>
                    <input type="text" name="txtplaca" id="txtplaca" value="" class="formularioPesquisa">
                </div>
                <br>
                <div>
                    <input type="submit" name="btnPesquisar" id="btnPesquisar" value="pesquisar" class="button">
                </div>
            </form>
        </fieldset>
    </div>
    <br>
    <div id="grid"> 
        <?php for($i=0; $i<count($historicoOfina); $i++){  ?>
           <table>
        	<thead>
            	<tr>
                    <td>Código</td>
                    <td>Data Entrada</td>
                    <td>Data Saída</td>
                    <td>Placa</td>
                    <td>Oficina</td>                   
                </tr>
            </thead> 
            <tbody>            
            	<tr>
                    <td><?=$historicoOfina[$i]['id']?></td>
                    <td><?=Util::bdDataHora($historicoOfina[$i]['dataEntrada'])?></td>
                    <td>
                    <?php
                        if(!empty($historicoOfina[$i]['dataSaida'])){
                            echo Util::bdDataHora($historicoOfina[$i]['dataSaida']);
                        }else{
                            echo "----";
                        }
                    ?>
                    </td>
                    <td><?=$historicoOfina[$i]['placa']?></td>
                    <td><?=utf8_encode($historicoOfina[$i]['empresa'])?></td>
                </tr>
                <tr>
                    <td colspan="5" style="background: #FFF">
                        <table>
                            <thead>
                            <tr>
                                <td>Data</td>
                                <td>Descrição</td>
                                <td>Valor</td>
                            </tr>
                            </thead> 
                            <tbody>
                        <?php $soma=0; for($j=0; $j<count($detalheHistorico[$i]); $j++){ $soma+=$detalheHistorico[$i][$j]["valor"]; ?>
                            <tr>
                                <td><?=Util::bdDataHora($detalheHistorico[$i][$j]["data"])?></td>
                                <td><?=utf8_encode($detalheHistorico[$i][$j]["descricao"])?></td>
                                <td><?=Util::dbMoeda($detalheHistorico[$i][$j]["valor"])?></td>
                            </tr>
                        <?php } ?>                            
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td><strong><span style="color: green"><?=Util::dbMoeda($soma)?></span></strong></td>
                                </tr>
                            </tfoot>
                        </table>
                    </td>
                </tr>
            </tbody>
           </table>
        <?php } ?>
    </div>
</div>
<?php require_once("../../includes_view/footer.php"); ?>